package com.spring.sunflower.userinfo;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.spring.sunflower.R;
import com.spring.sunflower.bean.VideoListBean;
import com.spring.sunflower.util.DisplayUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Created by Kevin on 2021/7/2<br/>
 * <p>
 * Describe:<br/>
 */
public class VideoShowListAdapter extends BaseQuickAdapter<VideoListBean.DatasBean, BaseViewHolder> {
    public VideoShowListAdapter(int layoutResId, @Nullable List<VideoListBean.DatasBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, VideoListBean.DatasBean datasBean) {
        RoundedImageView image = baseViewHolder.getView(R.id.rivImage);
        ImageView ivPlay = baseViewHolder.getView(R.id.ivPlay);
        TextView tvChecking = baseViewHolder.getView(R.id.tvChecking);
        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(-2, -2);
        int screenWidth = DisplayUtils.getScreenWidth(getContext());
        int i = DisplayUtils.dip2px(getContext(), 50);
        int imageWidth = (screenWidth - i) / 3;
        layoutParams.width = imageWidth;
        layoutParams.height = imageWidth * 3 / 2;
        image.setLayoutParams(layoutParams);
        if (datasBean.isPlaceHolder()) {
            Glide.with(getContext())
                    .load(R.drawable.ic_add)
                    .into((ImageView) image);
            ivPlay.setVisibility(View.GONE);
            tvChecking.setVisibility(View.GONE);
        } else {

            Glide.with(getContext())
                    .load(datasBean.getVideoFirstPhotoUrl())
                    .into((ImageView) image);
            ivPlay.setVisibility(View.VISIBLE);
            tvChecking.setVisibility(datasBean.getIsVerify().equals("1") ? View.GONE : View.VISIBLE);
            if (datasBean.getIsVerify().equals("0")) {
                tvChecking.setText("审核中");
            } else if (datasBean.getIsVerify().equals("2")) {
                tvChecking.setText("拒绝");
            }
        }
        RoundedImageView rivDelete = baseViewHolder.getView(R.id.rivDelete);
        rivDelete.setVisibility(datasBean.isShowDelete() && !datasBean.isPlaceHolder() ? View.VISIBLE : View.GONE);
    }
}
